package com.intelligent.system.auth.controller;

import com.intelligent.system.auth.dto.StaffInfoDTO;
import com.intelligent.system.auth.dto.UserDTO;
import com.intelligent.system.auth.service.IUserService;
import com.intelligent.system.common.response.ResultDO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.security.oauth2.client.OAuth2AuthorizedClient;
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientService;
import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken;
import org.springframework.security.oauth2.core.oidc.user.OidcUser;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.view.RedirectView;
import org.springframework.web.util.UriComponentsBuilder;

import javax.annotation.Resource;
import javax.servlet.ServletException;

@Api(tags = "OAuth2认证")
@RestController
@RequestMapping("/api/oauth")
public class OAuth2Controller {
    @Resource
    private IUserService userService;

    @ApiOperation("OAuth2回调处理")
    @GetMapping("/token-callback")
    public void handleCallback(
            @ApiParam("认证信息") Authentication authentication) {
       if(ObjectUtils.isNotEmpty(authentication)) {
           userService.register(authentication);
       }
    }
} 